version 17
set more off
quietly log
local logon = r(status)
	if "`logon'" == "on"  {
	log close	
	}
log using analysis_unwelcome_immigrants_knocking_on_the_door, text replace

/*******************************************************************************
	Project   : Unwelcome Immigrants Knocking on the Door
	File Name : analysis_unwelcome_immigrants_knocking_on_the_door.do
	Date	  : Feb 22nd, 2023 (Latest update)
	Purpose	  : Conducting the analysis that is included in the paper.
	Input	  : 1) data_unwelcome_immigrants_knocking_on_the_door.dta           - Final Data set
	Output	  : 1) analysis_unwelcome_immigrants_knocking_on_the_door.log       - Log File
					
******************************************************************************  */

**# 1. Calling the final data set
use "data_unwelcome_immigrants_knocking_on_the_door.dta", clear
gen log_gdppc = log(gdppc_wb_ipo)
gen log_gdppc_lag = log(gdppc_wb_ipo_lag)
gen immi_econ = total_immi_per_pop_ipo_lag * econ_index_ipo_lag
gen immi_working1564 = total_immi_per_pop_ipo_lag * working1564_per_ipo_lag
gen immi_working2455 = total_immi_per_pop_ipo_lag * working2455_per_ipo_lag
gen total_immigration_million = total_immi_ipo/1000000
replace cnt_unemployment_ilo_wb_lag = cnt_unemployment_ilo_wb_lag/100

**# 2. Descriptive Analysis
	* Immigration trends
		*a. The number of immigrants
		twoway line total_immigration_million year if country_name_n == 1, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																 graphregion(color(white)) bgcolor(white) title("Argentina") xtitle("") name(argentina, replace)
		twoway line total_immigration_million year if country_name_n == 2, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Bolivia")  xtitle("") name(bolivia, replace)
		twoway line total_immigration_million year if country_name_n == 3, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Brazil")  xtitle("") name(brazil, replace)												
		twoway line total_immigration_million year if country_name_n == 4, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Chile") xtitle("") name(chile, replace)
		twoway line total_immigration_million year if country_name_n == 5, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Colombia") xtitle("") name(colombia, replace)															 
		twoway line total_immigration_million year if country_name_n == 6, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Ecuador") xtitle("") name(ecuador, replace)															 
		twoway line total_immigration_million year if country_name_n == 7, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Paraguay") xtitle("") name(paraguay, replace)
		twoway line total_immigration_million year if country_name_n == 8, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Peru") xtitle("") name(peru, replace)															 
		twoway line total_immigration_million year if country_name_n == 9, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Uruguay") xtitle("") name(uruguay, replace)
		twoway line total_immigration_million year if country_name_n == 10, ytitle(Number of Immigrants (Million)) ylabel(0 1.0 2.0, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Venezuela") xtitle("") name(venezuela, replace)														 
		graph combine argentina	bolivia	brazil chile colombia ecuador paraguay peru	uruguay	venezuela, graphregion(color(white))
		
		*b. The proportion of immigrants
		twoway line total_immi_per_pop_ipo year if country_name_n == 1, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																 graphregion(color(white)) bgcolor(white) title("Argentina") xtitle("") name(argentina, replace)
		twoway line total_immi_per_pop_ipo year if country_name_n == 2, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Bolivia")  xtitle("") name(bolivia, replace)
		twoway line total_immi_per_pop_ipo year if country_name_n == 3, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Brazil")  xtitle("") name(brazil, replace)												
		twoway line total_immi_per_pop_ipo year if country_name_n == 4, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Chile") xtitle("") name(chile, replace)
		twoway line total_immi_per_pop_ipo year if country_name_n == 5, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Colombia") xtitle("") name(colombia, replace)															 
		twoway line total_immi_per_pop_ipo year if country_name_n == 6, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Ecuador") xtitle("") name(ecuador, replace)															 
		twoway line total_immi_per_pop_ipo year if country_name_n == 7, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Paraguay") xtitle("") name(paraguay, replace)
		twoway line total_immi_per_pop_ipo year if country_name_n == 8, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Peru") xtitle("") name(peru, replace)															 
		twoway line total_immi_per_pop_ipo year if country_name_n == 9, ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Uruguay") xtitle("") name(uruguay, replace)
		twoway line total_immi_per_pop_ipo year if country_name_n == 10,ytitle(Immigrants (% of Population)) ylabel(0 0.1, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Venezuela") xtitle("") name(venezuela, replace)														 
		graph combine argentina	bolivia	brazil chile colombia ecuador paraguay peru	uruguay	venezuela, graphregion(color(white))
		
		*c. The Economic index of immigrants
		twoway line econ_index_ipo year if country_name_n == 1, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																 graphregion(color(white)) bgcolor(white) title("Argentina") xtitle("") name(argentina, replace)
																 
		twoway line econ_index_ipo year if country_name_n == 2, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Bolivia")  xtitle("") name(bolivia, replace)
																	 
		twoway line econ_index_ipo year if country_name_n == 3, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Brazil")  xtitle("") name(brazil, replace)
																	 
		twoway line econ_index_ipo year if country_name_n == 4, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Chile") xtitle("") name(chile, replace)
																	 
		twoway line econ_index_ipo year if country_name_n == 5, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Colombia") xtitle("") name(colombia, replace)															 
		twoway line econ_index_ipo year if country_name_n == 6, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Ecuador") xtitle("") name(ecuador, replace)															 
		twoway line econ_index_ipo year if country_name_n == 7, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Paraguay") xtitle("") name(paraguay, replace)
																	 
		twoway line econ_index_ipo year if country_name_n == 8, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Peru") xtitle("") name(peru, replace)															 
		twoway line econ_index_ipo year if country_name_n == 9, ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Uruguay") xtitle("") name(uruguay, replace)
																	 
		twoway line econ_index_ipo year if country_name_n == 10,ytitle(Average GDP pc) ylabel(4000 25000) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Venezuela") xtitle("") name(venezuela, replace)														 
		graph combine argentina	bolivia	brazil chile colombia ecuador paraguay peru	uruguay	venezuela, graphregion(color(white))
		
		*d. The proportion of working-age immigrants
		twoway line working1564_per_ipo year if country_name_n == 1, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																 graphregion(color(white)) bgcolor(white) title("Argentina") xtitle("") name(argentina, replace)
																 
		twoway line working1564_per_ipo year if country_name_n == 2, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Bolivia")  xtitle("") name(bolivia, replace)
																	 
		twoway line working1564_per_ipo year if country_name_n == 3, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Brazil")  xtitle("") name(brazil, replace)												
		twoway line working1564_per_ipo year if country_name_n == 4, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Chile") xtitle("") name(chile, replace)
																	 
		twoway line working1564_per_ipo year if country_name_n == 5, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Colombia") xtitle("") name(colombia, replace)															 
		twoway line working1564_per_ipo year if country_name_n == 6, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Ecuador") xtitle("") name(ecuador, replace)															 
		twoway line working1564_per_ipo year if country_name_n == 7, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Paraguay") xtitle("") name(paraguay, replace)
																	 
		twoway line working1564_per_ipo year if country_name_n == 8, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Peru") xtitle("") name(peru, replace)															 
		twoway line working1564_per_ipo year if country_name_n == 9, ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Uruguay") xtitle("") name(uruguay, replace)
																	 
		twoway line working1564_per_ipo year if country_name_n == 10,ytitle(working age immigrants(%)) ylabel(0.4 0.9, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Venezuela") xtitle("") name(venezuela, replace)														 
		graph combine argentina	bolivia	brazil chile colombia ecuador paraguay peru	uruguay	venezuela, graphregion(color(white))
		
	* Proportion of natives with populist attitudes(%)
		twoway line prop_open_auto year if country_name_n == 1, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																 graphregion(color(white)) bgcolor(white) title("Argentina") xtitle("") name(argentina, replace)
		twoway line prop_open_auto year if country_name_n == 2, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Bolivia")  xtitle("") name(bolivia, replace)
		twoway line prop_open_auto year if country_name_n == 3, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Brazil")  xtitle("") name(brazil, replace)								
		twoway line prop_open_auto year if country_name_n == 4, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Chile") xtitle("") name(chile, replace)
		twoway line prop_open_auto year if country_name_n == 5, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Colombia") xtitle("") name(colombia, replace)								 
		twoway line prop_open_auto year if country_name_n == 6, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Ecuador") xtitle("") name(ecuador, replace)						 
		twoway line prop_open_auto year if country_name_n == 7, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Paraguay") xtitle("") name(paraguay, replace)
		twoway line prop_open_auto year if country_name_n == 8, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Peru") xtitle("") name(peru, replace)								 
		twoway line prop_open_auto year if country_name_n == 9, ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Uruguay") xtitle("") name(uruguay, replace)
		twoway line prop_open_auto year if country_name_n == 10,ytitle("") ylabel(0 0.6, format(%5.1f)) xlabel(2000 2009 2018) ///
																	 graphregion(color(white)) bgcolor(white) title("Venezuela") xtitle("") name(venezuela, replace)
		graph combine argentina	bolivia	brazil chile colombia ecuador paraguay peru	uruguay	venezuela, graphregion(color(white))

	*Descriptive statistics
	asdoc tab country year,m
	
	asdoc summarize open_auto_binary age male educ_three employed income_four_mean ideology_right catholic religiosity ///
			  total_immi_per_pop_ipo_lag econ_index_ipo_lag working1564_per_ipo_lag working2455_per_ipo_lag male_per_ipo_lag ///
			  log_gdppc_lag cnt_unemployment_ilo_wb_lag, dec(2)
			  
**# Statistical analysis
	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag  ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] ||year:
	est store m1

	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] ||year:
	est store m2

	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] ||year:
	est store m3
		 
	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working2455_per_ipo_lag immi_working2455 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] ||year:
	est store m4

	esttab m1 m2 m3 m4 ///
		using immigration-table2_per.rtf, replace b(%9.3f) ///
		stats(N ll) ///
		star(* .05 ** .01 *** .001) ///
		mlabel("Model 1" "Model 2" "Model 3" "Model 4") ///
		varlabels(age "Age" male "Male" ///
		educ_three "Education" employed "Employment" high_occupation "High Occupation" ///
		income_four_mean "Income" ideology_right "Ideology (Right)" catholic "Catholic" ///
		religiosity "Religiosity" ///
		total_immi_per_pop_ipo_lag "Total Immigrants (% of Population)" ///
		econ_index_ipo_lag "Average GDP pc of Immigrants" ///
		working1564_per_ipo_lag "Working-age Immigrants (15-64)(% of Immigrants)" ///
		working2455_per_ipo_lag "Working-age Immigrants (24-55)(% of Immigrants)" ///
		male_per_ipo_lag "Male Immigrants (% of Immigrants)" ///
		log_gdppc "ln(GDP pc)" unemployment "Unemployment Rate(%)")

	*Model 5
	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] if econ_index_ipo_lag < 12188.81 ||year: 
	est store m5_poor

	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] if econ_index_ipo_lag >12188.81 ||year: 
	est store m5_rich

	*Model 6
	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] if working1564_per_ipo_lag <0.6534 ||year:
	est store m6_less
	melogit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt] if working1564_per_ipo_lag >0.77 ||year:
	est store m6_more

	*Marginal Effect
	est restore m2
	grinter total_immi_per_pop_ipo_lag, inter(immi_econ) const02(econ_index_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Average GDP pc of immigrants' home countries) ytitle(Marginal effect of Immigration (% of Population))

	est restore m3
	grinter total_immi_per_pop_ipo_lag, inter(immi_working1564) const02(working1564_per_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Working-age immigrations of total immigrants) ytitle(Marginal effect of Immigration (% of Population)) 

	est restore m4
	grinter total_immi_per_pop_ipo_lag, inter(immi_working2455) const02(working2455_per_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Working-age immigrations of total immigrants) ytitle(Marginal effect of Immigration (% of Population))
			
	est restore m5_poor
	grinter total_immi_per_pop_ipo_lag, inter(immi_working1564) const02(working1564_per_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Working-age immigrations of total immigrants) ytitle(Marginal effect of Immigration (% of Population)) name(m5_poor_figure)
	est restore m5_rich
	grinter total_immi_per_pop_ipo_lag, inter(immi_working1564) const02(working1564_per_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Working-age immigrations of total immigrants) ytitle(Marginal effect of Immigration (% of Population)) name(m5_rich_figure)
	graph combine m5_poor_figure m5_rich_figure

	est restore m6_less
	grinter total_immi_per_pop_ipo_lag, inter(immi_econ) const02(econ_index_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Average GDP pc of immigrants' home countries) ytitle(Marginal effect of Immigration (% of Population))
			
	est restore m6_more
	ereturn list
	grinter total_immi_per_pop_ipo_lag, inter(immi_econ) const02(econ_index_ipo_lag) ///
			depvar(open_auto_binary) equation(open_auto_binary) ///
			nomean nomeantext kdensity clevel(95) dof(16) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Average GDP pc of immigrants' home countries) ytitle(Marginal effect of Immigration (% of Population))

**# Robust Check
	*Different Model Specification
	*Clustered Standard errors
	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag  ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt],cluster(year)
	est store m1_clu

	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt],cluster(year)
	est store m2_clu

	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt],cluster(year)
	est store m3_clu
		 
	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working2455_per_ipo_lag immi_working2455 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n [pw=wt],cluster(year)
	est store m4_clu

	esttab m1_clu m2_clu m3_clu m4_clu ///
		using immigration-table_clu.rtf, replace b(%9.3f) ///
		stats(N ll) ///
		star(* .05 ** .01 *** .001) ///
		mlabel("Model 1" "Model 2" "Model 3" "Model 4") ///
		varlabels(age "Age" male "Male" ///
		educ_three "Education" employed "Employment" high_occupation "High Occupation" ///
		income_four_mean "Income" ideology_right "Ideology (Right)" catholic "Catholic" ///
		religiosity "Religiosity" ///
		total_immi_per_pop_ipo_lag "Total Immigrants (% of Population)" ///
		econ_index_ipo_lag "Average GDP pc of Immigrants" ///
		working1564_per_ipo_lag "Working-age Immigrants (15-64)(% of Immigrants)" ///
		working2455_per_ipo_lag "Working-age Immigrants (24-55)(% of Immigrants)" ///
		male_per_ipo_lag "Male Immigrants (% of Immigrants)" ///
		log_gdppc "ln(GDP pc)" unemployment "Unemployment Rate(%)")
	
	*year fixed effects
	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag  ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n i.year [pw=wt]
	est store m1_fix

	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n i.year [pw=wt]
	est store m2_fix

	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n i.year [pw=wt]
	est store m3_fix
		 
	logit open_auto_binary ///
			age male educ_three employed income_four_mean ideology_right ///
			catholic religiosity ///
			total_immi_per_pop_ipo_lag working2455_per_ipo_lag immi_working2455 ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
			i.country_name_n i.year [pw=wt]
	est store m4_fix
			
	esttab m1_fix m2_fix m3_fix m4_fix ///
		using immigration-table_fix.rtf, replace b(%9.3f) ///
		stats(N ll) ///
		star(* .05 ** .01 *** .001) ///
		mlabel("Model 1" "Model 2" "Model 3" "Model 4") ///
		varlabels(age "Age" male "Male" ///
		educ_three "Education" employed "Employment" high_occupation "High Occupation" ///
		income_four_mean "Income" ideology_right "Ideology (Right)" catholic "Catholic" ///
		religiosity "Religiosity" ///
		total_immi_per_pop_ipo_lag "Total Immigrants (% of Population)" ///
		econ_index_ipo_lag "Average GDP pc of Immigrants" ///
		working1564_per_ipo_lag "Working-age Immigrants (15-64)(% of Immigrants)" ///
		working2455_per_ipo_lag "Working-age Immigrants (24-55)(% of Immigrants)" ///
		male_per_ipo_lag "Male Immigrants (% of Immigrants)" ///
		log_gdppc "ln(GDP pc)" unemployment "Unemployment Rate(%)")

**# DV: Anti-immigration attitude
	tab anti_immi_job      ,m
	recode anti_immi_job (-1=.)
	
	*The realtionship between anti-immigration and immigration
	meologit anti_immi_job ///
		  age male educ_three employed income_four_mean ideology_right ///
		  catholic religiosity ///
		  total_immi_per_pop_ipo_lag  ///
		  male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
		  i.country_name_n [pw=wt] || year:
	est store job_immi_1
	
	meologit anti_immi_job ///
		  age male educ_three employed income_four_mean ideology_right ///
		  catholic religiosity ///
		  total_immi_per_pop_ipo_lag econ_index_ipo_lag immi_econ ///
			male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
		  i.country_name_n [pw=wt] || year:
	est store job_immi_2
	
	meologit anti_immi_job ///
		  age male educ_three employed income_four_mean ideology_right ///
		  catholic religiosity ///
		  total_immi_per_pop_ipo_lag working1564_per_ipo_lag immi_working1564 ///
		  male_per_ipo_lag log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
		  i.country_name_n [pw=wt] || year:
	est store job_immi_3
	
	esttab job_immi_1 job_immi_2 job_immi_3 ///
		using immi_atti_table_fix_2.rtf, replace b(%9.3f) ///
		stats(N ll) ///
		star(+ 0.1 * .05 ** .01 *** .001) ///
		mlabel("Model 1" "Model 2" "Model 3" "Model 4") ///
		varlabels(age "Age" male "Male" ///
		educ_three "Education" employed "Employment" high_occupation "High Occupation" ///
		income_four_mean "Income" ideology_right "Ideology (Right)" catholic "Catholic" ///
		religiosity "Religiosity" ///
		total_immi_per_pop_ipo_lag "Total Immigrants (% of Population)" ///
		econ_index_ipo_lag "Average GDP pc of Immigrants" ///
		working1564_per_ipo_lag "Working-age Immigrants (15-64)(% of Immigrants)" ///
		working2455_per_ipo_lag "Working-age Immigrants (24-55)(% of Immigrants)" ///
		male_per_ipo_lag "Male Immigrants (% of Immigrants)" ///
		log_gdppc "ln(GDP pc)" unemployment "Unemployment Rate(%)")
		
	tab econ_index if anti_immi_job!=.
	summarize econ_index, detail
	summarize econ_index if anti_immi_job!=., detail
	
	twoway (hist econ_index, frac lcolor(gs12) fcolor(gs12)) (hist econ_index if anti_immi_job!=. , frac fcolor(none) lcolor(red)), legend(off) xtitle("Economic index of immigrants (red: restricted)")
	
	est restore job_immi_2
	grinter total_immi_per_pop_ipo_lag, inter(immi_econ) const02(econ_index_ipo_lag) ///
			depvar(anti_immi_job) equation(anti_immi_job) ///
			nomean nomeantext kdensity clevel(90) dof(4) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Average GDP pc of immigrants' home countries) ytitle(Marginal effect of Immigration (% of Population))
	
	est restore job_immi_3
	grinter total_immi_per_pop_ipo_lag, inter(immi_working1564) const02(working1564_per_ipo_lag) ///
			depvar(anti_immi_job) equation(anti_immi_job) ///
			nomean nomeantext kdensity clevel(95) dof(4) graphregion(col(white)) bgcol(white) yline(0) ///
			xtitle(Working-age immigrations of total immigrants) ytitle(Marginal effect of Immigration (% of Population)) 
			
	*The realtionship between populist attitudes and anti-immigration
	melogit open_auto_binary anti_immi_job ///
		  age male educ_three employed income_four_mean ideology_right ///
		  catholic religiosity ///
		  log_gdppc_lag cnt_unemployment_ilo_wb_lag ///
		  i.country_name_n [pw=wt] || year:
	est store job_1
	
	esttab job_1 ///
		using immi_atti_populism_table_fix.rtf, replace b(%9.3f) ///
		stats(N ll) ///
		star(* .05 ** .01 *** .001) ///
		mlabel("Model 1" "Model 2" "Model 3") ///
		varlabels(age "Age" male "Male" ///
		educ_three "Education" employed "Employment" high_occupation "High Occupation" ///
		income_four_mean "Income" ideology_right "Ideology (Right)" catholic "Catholic" ///
		religiosity "Religiosity" ///
		log_gdppc "ln(GDP pc)" unemployment "Unemployment Rate(%)")

log close
clear